<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<link rel="stylesheet" type="text/css" href="css/admin.css">
</head>
<body>
	<a class="a" href='homepage.php'>回到主页</a>
	<a class="a" href='register.php'>注册新用户</a>
<?php
if (isset($_COOKIE['user']) && $_COOKIE['admin'] == 1) {
} else {
    echo "<script>alert('请您登录');window.location.href='index.php';</script>";
}

echo "管理员" . $_COOKIE['user'];

require_once("tools.php");

$con      = new con_db();

$sql      = "SELECT * FROM persons";
$result   = $con->query($sql);
$totalnum = $result->num_rows;
echo "<br><br>用户总数" . $totalnum;
echo "<br><br><table border='1' ><tr><th>账号</th><th>管理员</th><th>修改</th><th>可登陆</th><th>修改</th></tr>";

while ($row = $result->fetch_assoc()) {
    echo "<tr><td>" . $row['zhanghao'] . "</td><td>";
    if ($_COOKIE['user'] == 111) {
        if ($row['admin'] == 1) {
            if ($row['zhanghao'] == 111)
                echo "超级管理员</td><td></td><td>";
            else
                echo "管理员</td><td><form action='loginright.php' method='post'><input type='text' name='idadmin' style='display:none;' value='" . $row['zhanghao'] . "'><input type='text' name='value' style='display:none;' value='0'><input type='submit'  value='关闭权限'></form></td><td>";
        } else {
            echo "否</td><td><form action='loginright.php' method='post'><input type='text' name='idadmin' style='display:none;' value='" . $row['zhanghao'] . "'><input type='text' name='value' style='display:none;' value='1'><input type='submit'  value='授&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;权'></form></td><td>";
        }
    } else {
        if ($row['admin'] == 1 && $row['zhanghao'] == 111) {
            echo "超级管理员</td><td></td><td>";
        } else if ($row['admin'] == 1) {
            echo "管理员</td><td></td><td>";
        } else {
            echo "否</td><td></td><td>";
        }
    }
    if ($row['loginright'] == 1) {
        if ($row['zhanghao'] == 111)
            echo "是</td><td></td></tr>";
        else if ($_COOKIE['user'] != 111 && $row['admin'] == 1)
            echo "是</td><td></td></tr>";
        else
            echo "是</td><td><form action='loginright.php' method='post'><input type='text' name='idloginright' style='display:none;' value='" . $row['zhanghao'] . "'><input type='text' name='value' style='display:none;' value='0'><input type='submit'  value='禁止登陆'></form></td></tr>";
    }
    
    else {
        if ($row['zhanghao'] == '')
            echo "被禁止</td><td></td></tr>";
        else if ($_COOKIE['user'] != 111 && $row['admin'] == 1)
            echo "被禁止</td><td></td></tr>";
        else
            echo "被禁止</td><td><form action='loginright.php' method='post'><input type='text' name='idloginright' style='display:none;' value='" . $row['zhanghao'] . "'><input type='text' name='value' style='display:none;' value='1'><input type='submit'  value='解禁'></form>
		</td></tr>";
    }
}
echo "</table>";

$file    = 'logs.txt';
$content = '';
if (is_file($file)) {
    $content = file_get_contents($file); // 一次性取完
}
$encode     = mb_detect_encoding($content, array(
    "ASCII",
    'UTF-8',
    "GB2312",
    "GBK",
    'BIG5'
));
$str_encode = mb_convert_encoding($content, 'UTF-8', $encode);
echo "<h2>用户意见反馈</h2><br>qq号码<br>";
echo '<pre>' . htmlspecialchars($str_encode) . '</pre>'; // 这个是原格式
?>
</body>
</html>